package com.tencent.yolov5ncnn

import android.app.Activity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import android.widget.TextView
import com.android.volley.VolleyError
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley
import com.android.volley.Request
import com.android.volley.Response
import org.json.JSONObject

class network : Activity() {
    private var getmes :TextView?=null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_network)


       val sendmes=findViewById<TextView>(R.id.sendmes)
        getmes=findViewById(R.id.getmes)

        sendmes.setOnClickListener({
            getMethod()
        })

    }
    fun getMethod(){
        // 1 创建一个请求队列
        val requestQueue = Volley.newRequestQueue(this)
// 2 创建一个请求
        val url = "http://8.137.57.138:8080/already"
        val stringRequest = StringRequest(
            Request.Method.GET, url,
            { response ->
                // 正确接收数据回调
                getmes?.text ="onResponse: $response"
                Log.e("AppDebug", "onResponse: $response")
            },
            { error ->
                // 发生异常后的监听回调
                Log.e("AppDebug", "onErrorResponse: $error")
            }
        )
// 3 将创建的请求添加到请求队列中
        requestQueue.add(stringRequest)
    }

}